package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.goods.entity.XcxGoods;
import com.ibiaoke.goods.service.XcxGoodsService;
import com.ibiaoke.order.entity.XcxOrder;
import com.ibiaoke.order.entity.so.XcxOrderSO;
import com.ibiaoke.order.entity.vo.DateAnalysisVO;
import com.ibiaoke.order.entity.vo.XcxOrderVO;
import com.ibiaoke.order.service.XcxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author Healer
 * @date 2018/3/9/9:51;
 */
@Controller
public class BossXcxOrderController extends BaseController {

    @Autowired
    private XcxOrderService xcxOrderService;

    @Autowired
    private XcxGoodsService xcxGoodsService;

    @RequestMapping("/listXcxOrder")
    @ResponseBody
    public Res listXcxOrder(XcxOrderVO xcxOrder, Page page) {
        List<XcxOrder> xcxOrderList = xcxOrderService.xcxOrderList(xcxOrder, page);
        return Res.create()
                .addResponse("xcxOrderList",xcxOrderList)
                .addResponse("page",page);
    }

    @ResponseBody
    @RequestMapping("/getXcxOrderByOrderId")
    public Res getXcxOrderByOrderId(Integer xcxOrderId) {
        XcxOrder xcxOrder = xcxOrderService.getXcxOrderByOrderId(xcxOrderId);
        return Res.create().addResponse("xcxOrder", xcxOrder);
    }

    /**
     * 获取当天对应门店的销售详情
     *
     * @param xcxOrderSO
     * @return
     */
    @RequestMapping("/getXcxDateAnalysisToday")
    @ResponseBody
    public Res getDateAnalysisToday(XcxOrderSO xcxOrderSO) {
        HashMap<String, DateAnalysisVO> dateAnalysisVO = xcxOrderService.getTodayOrderData(xcxOrderSO, null);
        return new Res().addResponse("dateAnalysisVO", dateAnalysisVO);
    }

    /**
     * 根据传入时间来查询对应门店的历史销售详情
     *
     * @param xcxOrderSO
     * @return
     */
    @RequestMapping("/getXcxDateAnalysisByDate")
    @ResponseBody
    public Res getDateAnalysisByDate(XcxOrderSO xcxOrderSO) {
        HashMap<String, DateAnalysisVO> dateAnalysisVO = xcxOrderService.getOrderAnalysis(xcxOrderSO,null);
        return new Res().addResponse("dateAnalysisVO", dateAnalysisVO);
    }

    @RequestMapping("/xcxAggregate")
    @ResponseBody
    public Res xcxAggregate(Integer serviceNum, Date startTime, Date endTime) {
        String bounty = xcxOrderService.aggregate(serviceNum, startTime, endTime);
        return Res.create().addResponse("bounty",bounty);
    }
}
